﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Tiens.NotificationHub.Core.Options;
using Tiens.NotificationHub.Core.Services;
using Tiens.NotificationHub.Core.Utils;

namespace Tiens.NotificationHub.Core.Extensions
{
    public static class AuthorizationServiceCollectionExtension
    {
        public static IServiceCollection AddUserAuthorization(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddOptions<MockOptions>()
                .Configure(configuration.GetSection(nameof(MockOptions)).Bind);

            services.AddOptions<CBCOptions>()
                .Configure(configuration.GetSection(nameof(CBCOptions)).Bind);

            services.AddScoped<CBCDecryptor>();
            services.AddSingleton<InMemoryTokenManager>();

            return services.AddTransient<IAuthorizationHandler, UserAuthorizationHandler>();
        }
    }
}
